package com.zxmc.server.controller.user;

import com.zxmc.common.result.PageResult;
import com.zxmc.common.result.Result;
import com.zxmc.pojo.dto.NovelQueryDto;
import com.zxmc.pojo.dto.PageNovelQueryDto;
import com.zxmc.pojo.entity.Novel;
import com.zxmc.pojo.vo.NovelVO;
import com.zxmc.server.service.NovelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/novel")
@Slf4j
@Api(tags = "小说相关接口")
public class NovelController {
    @Autowired
    private NovelService novelService;

    @GetMapping("/list")
    @ApiOperation("查询小说数据(条件查询)")
    public Result<List<Novel>> list(NovelQueryDto novelQueryDto) {
        log.info("查询小说数据{}", novelQueryDto);
        List<Novel> novels= novelService.list(novelQueryDto);
        return Result.success(novels);
    }
    @GetMapping("/listAuthorBooks")
    @ApiOperation("查询作者小说数据")
    public Result<List<Novel>> listAuthorBooks(NovelQueryDto novelQueryDto) {
        log.info("查询作者小说数据{}", novelQueryDto.getAuthor());
        List<Novel> novels= novelService.listByAuthor(novelQueryDto.getAuthor());
        return Result.success(novels);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询小说数据(条件查询)")
    public Result<PageResult> page(PageNovelQueryDto pageNovelQueryDto) {
        log.info("分页查询小说数据{}", pageNovelQueryDto);
        PageResult pageResult = novelService.page(pageNovelQueryDto);
//        System.out.println(pageResult);
        return Result.success(pageResult);
    }


}
